﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XLua;

public class XLuaManager : MonoBehaviour {
    public LuaEnv luaenv = null;
    // Use this for initialization
    void Start () {
        luaenv = new LuaEnv();
        luaenv.DoString("require 'Main'");
        ToXluaMethod(1, 2, "Main");
    }
	
	// Update is called once per frame
	void Update () {
        if (luaenv != null)
        {
            luaenv.Tick();
        }
    }

    void OnDestroy()
    {
        luaenv.Dispose();
    }

    /// <summary>
    /// cs去调用Lua方法
    /// method      UIChanceWindow_newMsg
    /// </summary>
    /// <param name="type"></param>
    /// <param name="data"></param>
    /// <param name="method"></param>
    /// <returns></returns>
    [CSharpCallLua]
    public delegate int ToXluaMethodDel(object type, object data);
    public void ToXluaMethod(object o1, object o2, string luaMethodName)
    {
        //向lua层发消息
        ToXluaMethodDel f = luaenv.Global.Get<ToXluaMethodDel>(luaMethodName);
        f(o1, o2);
    }
}
